import sys
import urllib.request
import os

coreversion = input('请输入core端版本:')
mversion = input('请输入m端版本:')
pcversion = input('请输入pc端版本:')
fileversion = input('请输入文件服务器版本:')


#core
if coreversion != "":
    print("downloading YX_Core-"+coreversion+" with urllib.request")
    url = 'http://10.0.0.110:8110/nexus/service/local/repositories/YX-release/content/com/yxht/core/YX_Core/'+coreversion+'/YX_Core-'+coreversion+'.war'
    try:
        r = urllib.request.urlopen(url).read()
        with open("YX_Core.war", "wb") as code:
            code.write(r)
        print('downloading YX_Core-' + coreversion + '.war finished!')
    except:
        print("Unexpected error:", sys.exc_info()[0])

else:
    print("您未输入core端版本号，程序对core端将不进行处理")

#mobile
if mversion != "":
    print("downloading yx_mobile-"+mversion+" with urllib.request")
    url = 'http://10.0.0.110:8110/nexus/service/local/repositories/YX-release/content/com/yxht/yx_mobile/yx_mobile/'+mversion+'/yx_mobile-'+mversion+'.war'
    try:
        r = urllib.request.urlopen(url).read()
        with open("yx_mobile.war", "wb") as code:
            code.write(r)
        print('downloading yx_mobile-' + mversion + '.war finished!')
    except:
        print("Unexpected error:", sys.exc_info()[0])

else:
    print("您未输入mobile端版本号，程序对mobile端将不进行处理")

#pc
if pcversion != "":
    print("downloading yxhtWeb-"+pcversion+" with urllib.request")
    url = 'http://10.0.0.110:8110/nexus/service/local/repositories/YX-release/content/com/yxht/web/yxhtWeb/'+pcversion+'/yxhtWeb-'+pcversion+'.war'
    try:
        r = urllib.request.urlopen(url).read()
        with open("yxhtWeb.war", "wb") as code:
            code.write(r)
        print('downloading yxhtWeb-' + pcversion + '.war finished!')
    except:
        print("Unexpected error:", sys.exc_info()[0])

else:
    print("您未输入pc端版本号，程序对pc端将不进行处理")

#fileserver
if fileversion != "":
    print("downloading fileserver-"+fileversion+" with urllib.request")
    url = 'http://10.0.0.110:8110/nexus/service/local/repositories/YX-release/content/com/yxht/fileserver/YX_Sourceload/'+fileversion+'/YX_Sourceload-'+fileversion+'.war'
    try:
        r = urllib.request.urlopen(url).read()
        with open("YX_Sourceload.war", "wb") as code:
            code.write(r)
        print('downloading fileserver-' + fileversion + '.war finished!')
    except:
        print("Unexpected error:", sys.exc_info()[0])

else:
    print("您未输入文件服务器版本号，程序对文件服务器将不进行处理")

#调用tomcat
os.system('python3 bushu.py')